package com.mccrea.principle.ocp.improve;

/**
 * @Classname OcpAppmain
 * @Description 满足开闭原则的例子
 * @Date 2021/5/6 0006 18:53
 * @Created by Mccrea_Gao
 */
public class OcpAppmain {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Rectangle());
    }
}



class GraphicEditor {
    public void drawShape(Shape shape) {
        shape.draw();
    }
}

abstract class Shape {
    public abstract void draw();
}

class Circle extends Shape {
    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

class Rectangle extends Shape {
    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}